/**
 * Created by wyy on 17-7-7.
 */
angular.module('leftBar', []).component(
    'leftBar',
    {
        templateUrl: 'component/base/leftBar/left_bar.template.html',
        controller: ['$rootScope' ,'$scope', 'Enum', '$state','Api', function ($rootScope, $scope, Enum, $state,Api) {

            setupLeftContent($state.current.name);

            if(!$scope.selectItem)
            {
                 $scope.selectItem=Enum.StaffNormalLeftBarItems;
            }

            // console.log($state.current.name)

            /* 获取路由变化 */
            // $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
            //     setupLeftContent(toState.name);
            //     console.log(toState)
            // });


            function setupLeftContent(stateName) {

                setupLeftItems(stateName);
                setupSelectedItem(stateName);

                function setupLeftItems(stateName) {

                    if (stateName.indexOf('company.company') !== -1 || stateName === 'company'||stateName==='company.companyApartmentInfo') {

                        $scope.leftItems = Enum.StaffNormalLeftBarItems;
                    }
                }

                function getCompanyDetail() {
                    if(!Api.getAssign()){
                        return false;
                    }
                    Api.getCompanyDetail(Api.getAssign(), function (result) {
                        // if (!result.data.propertyNature) {
                        $scope.leftItems = Enum.StaffLeftBarItems;
                        // }
                    });
                }
            }
            function setupSelectedItem(stateName) {
                $scope.selectItem = Enum.StaffNormalLeftBarItems[0];
                //if (stateName === 'company.companyApartmentManage') {
                //
                //} else if (stateName === 'company.companyStaff'){
                //    $scope.selectItem = Enum.StaffNormalLeftBarItems[1];
                //
                //}
            }

            $scope.selectNavList=function (value) {
                $scope.selectItem=value;
            };
        }]
    }
);
